package taller2.controller.listeners.evaluateMeButtons;

import java.awt.event.ActionEvent;
import java.util.ArrayList;

import taller2.interfaces.AlgorithmApplicator;
import taller2.interfaces.Graph;
import taller2.interfaces.Node;
import taller2.model.factorys.GraphFactory;
import taller2.model.graph.algorithms.TopologicDFSApplicator;
import taller2.view.windows.supervisor.TopologicDfsSupervisorWindow;

public class TopoDfsEvaluateMeButtonListener extends EvaluateMeButtonListener{

	public TopoDfsEvaluateMeButtonListener(AlgorithmApplicator aplicator) {
		super(aplicator);
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		menu.unselectButtons();
		
		TopologicDFSApplicator dfs = (TopologicDFSApplicator)aplicator;
		
		String path = dfs.getStartingGraphPath();

		if(path != null){
			Graph g;
		
			boolean directed = dfs.wasDirected();
			if (directed){
				g = GraphFactory.directedGgraphInstance();
			}else{
				g = GraphFactory.undirectedGraphInstance();
			}
		
			g.load(path);
			g.unselectNodes();
			g.unselectConnections();
		
			ArrayList<Node> nodes = g.getNodes();
			int cantNodes = nodes.size();
		
			if(cantNodes > 0){
				new TopologicDfsSupervisorWindow(g);
			}
		}
	}
}
